//
//  DateSelectionViewController.m
//  CS Inventory Manager
//
//  Created by Ian Smith on 3/24/13.
//  Copyright (c) 2013 Transylvania University. All rights reserved.
//

#import "DateSelectionViewController.h"
#import "AgreementViewController.h"

@interface DateSelectionViewController ()

@end

@implementation DateSelectionViewController
@synthesize selectedItem, selectedPatron, cameFromDVC;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

//IBAction for the "Back" button
-(void)backButton:(id)sender
{
    //Dismiss the current screen and go back to the previous one
    [self dismissViewControllerAnimated:YES completion:NULL];
}

//IBAction that handles the "Next" button
-(void)nextButton:(id)sender
{
    NSDate *dateSelected = self.dateSelection.date;
    if ([dateSelected timeIntervalSinceNow] < 0) {
        //This means they are trying to set a due date in the past. Don't allow!
    } else {
        //Go ahead to next screen, they have selected a valid due date
        [self performSegueWithIdentifier:@"Agreement" sender:dateSelected];
    }
}

//Get ready for next screen here
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    //Just grab the upcoming screen and pass on everything that has been selected so far
    AgreementViewController *nextController = segue.destinationViewController;
    nextController.selectedItem = selectedItem;
    nextController.selectedPatron = selectedPatron;
    nextController.selectedDueDate = sender;
    nextController.cameFromDVC = cameFromDVC;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    self.dateSelection.date = [NSDate date];
    self.navBar.topItem.title = @"Check Out Wizard";
    self.view.backgroundColor = [UIColor grayColor];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
